﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GameBase;

namespace _0912089
{
    public abstract class View : VisibleGameEntity, ISubscriber
    {
        protected Texture2D _background;
        protected bool _visible = true;
        protected float _alpha = 1.0f;
        protected ActionHelper _action;

        public ActionHelper Action
        {
            get { return _action; }
            set { _action = value; }
        }

        public override void update(GameTime gameTime)
        {
            if (_action != null)
                _action.update(gameTime);
        }

        public float Alpha
        {
            get { return _alpha; }
            set { _alpha = value; }
        }

        public bool Visible
        {
            get { return _visible; }
            set { _visible = value; }
        }

        public Texture2D Background
        {
            get { return _background; }
            set { _background = value; }
        }

        public override void draw(GameTime gameTime, SpriteBatch spriteBatch, Color color)
        {
            if (Visible && Background != null)
                //spriteBatch.Draw(Background, new Rectangle((int)Position.X, (int)Position.Y, (int)(Scale * Size.X), (int)(Scale * Size.Y)), color * Alpha);
                spriteBatch.Draw(Background, new Rectangle((int)Position.X, (int)Position.Y, (int)(Scale * Size.X), (int)(Scale * Size.Y)),
                    null, color * Alpha, Rotation, Vector2.Zero, SpriteEffects.None, 0f);
        }

        #region ISubscriber
        public void subscribe(ITopic topic)
        {
            NotificationCenter.subscribe(topic.TopicName, this);
        }

        public void unSubscribe(ITopic topic)
        {
            NotificationCenter.unSubscribe(topic.TopicName, this);
        }

        public virtual bool notify(string message)
        {
            if(_action != null)
                _action.start();
            return true;
        }
        #endregion

        protected float _rotation;

        public virtual float Rotation
        {
            get { return _rotation; }
            set { _rotation = value; }
        }
    }
}
